package com.ody.util.code.config;

import com.google.common.collect.ImmutableMap;
import com.odianyun.util.string.StringPlaceHolderUtils;

public class MysqlJdbcConfig implements IJdbcConfig {
	private String host;
	private int port;
	private String username;
	private String password;
	private String db;
	
	public MysqlJdbcConfig(String host, int port, String username, String password, String db) {
		this.host = host;
		this.port = port;
		this.username = username;
		this.password = password;
		this.db = db;
	}

	@Override
	public String getJdbcDriver() {
		return "com.mysql.cj.jdbc.Driver";
	}

	@Override
	public String getJdbcUrl() {
		String urlTmpl = "jdbc:mysql://${host}:${port}/${db}?useUnicode=true&characterEncoding=UTF-8&useInformationSchema=true&serverTimezone=UTC";
		return StringPlaceHolderUtils.replace(urlTmpl, ImmutableMap.of("host", host, "port", port, "db", db));
	}

	@Override
	public String getJdbcUsername() {
		return username;
	}

	@Override
	public String getJdbcPassword() {
		return password;
	}
	
}
